package cn.tedu._06interceptor.config;

import cn.tedu._06interceptor.interceptor.MyInterceptor1;
import cn.tedu._06interceptor.interceptor.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/*
*WebMvcConfigurer springMVC 标准化配置接口 用于注册拦截器*/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //1.addInterceptors 用于添加拦截器(注册拦截器)
        //InterceptorRegistry拦截器参数
        //(1)拦截所有请求
        //--------registry.addInterceptor(new MyInterceptor1());


        //(2)拦截指定单个请求
        /* ----------------registry.addInterceptor(new MyInterceptor1())
                .addPathPatterns("/v1/users/reg");

         */
        //(3)拦截指定请求,拦截某模块所有请求
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/v1/users/**");

        //(4)排除指定请求,比如拦截用户模块除了登录之外所有请求
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/v1/users/**")
//                .excludePathPatterns("/v1/users/login");
        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());
    }
}

